package com.ysd.dao;




import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.ysd.entity.Permission;


public interface PermissionRepository extends JpaRepository<Permission, Integer>, JpaSpecificationExecutor<Permission> {

	
	@Query(value = "select MD5(now())", nativeQuery = true)
	Object getMD5();
	
	@Query(value = "SELECT p.permissionmodule FROM permission p GROUP BY p.permissionmodule", nativeQuery = true)
	List<Object> getTitles();

	@Query(value = "SELECT p.permissionid FROM permission p WHERE p.permissionmodule=?1 ", nativeQuery = true)
	List<Object> getIdsByTitle(Object Object);

	@Query(value = "SELECT p.permissionname FROM permission p WHERE p.permissionmodule=?1 ", nativeQuery = true)
	List<String> getChildByTitle(String ti);

	@Query(value = "SELECT p.permissionid FROM permission p WHERE p.permissionname=?1 and p.permissionmodule=?2 ", nativeQuery = true)
	List<String> getChildIdByChildTitle(String string, String ti);

	@Query(value = "SELECT rp.permissionid from rolepermission rp WHERE rp.rid=?1 ", nativeQuery = true)
	List<Object> getPerIdsByRoleId(Object id);

	@Query(value = "SELECT rp.permissionid from rolepermission rp WHERE rp.rid=?1 and rp.permissionid=?2 ", nativeQuery = true)
	List<Object> findPreByR_P(Object rid, Object pids);

	@Transactional
	@Modifying
	@Query(value = "INSERT INTO rolepermission (permissionid,rid) VALUES (?2, ?1)", nativeQuery = true)
	Integer addR_P(Object rid,String a);
	
	@Transactional
	@Modifying
	@Query(value = "delete from rolepermission where rid=?1 and permissionid=?2", nativeQuery = true)
	Integer delR_P(Object rid, String a);

	@Query(value = "SELECT rp.permissionid from rolepermission rp WHERE rp.rid=?1 ", nativeQuery = true)
	List<Object> findPresByRid(Object rid);

}
